<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="common/_header :: header">
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar" th:include="common/_aside :: aside">
        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header" th:include="common/_top :: top">
        </header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <form class="pull-right search-bar" method="get" action="#!" role="form">
                                    <div class="input-group">
                                        <div class="input-group-btn">
                                            <input type="hidden" name="search_field" id="search-field" value="title">
                                            <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                                                标题 <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li><a tabindex="-1" href="javascript:void(0)" data-field="title">省名</a></li>
                                                <li><a tabindex="-1" href="javascript:void(0)" data-field="cat_name">大区</a></li>
                                            </ul>
                                        </div>
                                        <input type="text" class="form-control" value="" name="keyword" placeholder="请输入名称">
                                    </div>
                                </form>
                                <div class="toolbar-btn-action">
                                    <a class="btn btn-primary" href="#!"><i class="mdi mdi-plus"></i> 启用</a>
                                    <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 禁用</a>
                                    <a class="btn btn-primary" href="#!" th:onclick="addProvince()"><i class="mdi mdi-plus"></i> 增加</a>
                                </div>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th width="5%">
                                                <label class="lyear-checkbox checkbox-primary">
                                                    <input type="checkbox" id="check-all"><span></span>
                                                </label>
                                            </th>
                                            <th>省名</th>
                                            <th>大区</th>
                                            <th>状态</th>
                                            <th width="10%">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr th:each="province:${provinceList}">
                                            <td>
                                                <label class="lyear-checkbox checkbox-primary">
                                                    <input type="checkbox" name="ids[]" value="1"><span></span>
                                                </label>
                                            </td>
                                            <td th:text="${province.name}"></td>
                                            <td th:text="${province.area}"></td>
                                            <td>
                                                <span th:if="${province.status ==1}" style="color: #0c5460;">开通</span>
                                                <span th:if="${province.status ==2}" style="color: #2D93CA;">未开通</span>
                                            </td>
                                            <td>
                                                <div class="btn-group">
                                                    <a class="btn btn-xs btn-default" href="#!" title="编辑" data-toggle="tooltip" th:onclick="updateProvince([[${province.id}]])"><i class="mdi mdi-pencil"></i></a>
                                                    <span th:if="${province.status ==1}">
                                                        <a class="btn btn-xs btn-default" href="#!" title="禁用" th:onclick="'changeStatus('+${province.id}+',2)'" data-toggle="tooltip"><i class="mdi mdi-lock"></i></a>
                                                    </span>
                                                    <span th:if="${province.status ==2}">
                                                        <a class="btn btn-xs btn-default" href="#!" title="启用" th:onclick="'changeStatus('+${province.id}+',1)'" data-toggle="tooltip"><i class="mdi mdi-lock-open"></i></a>
                                                    </span>
                                                    <a class="btn btn-xs btn-default" th:href="@{/city/v1/listCity(provinceId=${province.id})}" title="所辖市" data-toggle="tooltip"><i class="mdi mdi-apps"></i></a>
                                                </div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<div th:replace="common/_js :: js">
</div>

<!--对话框-->
<script th:src="@{/js/layer/layer.js}"></script>

<script type="text/javascript">
    function addProvince() {
        layer.open({
            type: 2,
            title: '省信息',
            shadeClose: true,
            shade: false,
            anim: 2,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '430px'],
            content: ['openProvinceAdd', 'no']
        });
    }
    function updateProvince(id) {
        layer.open({
            type: 2,
            title: '省信息',
            shadeClose: true,
            shade: false,
            anim: 2,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '490px'],
            content: ['openProvinceUpdate?id='+id, 'no']
        });
    }

    function changeStatus(id, status) {
        layer.confirm('您确定要修改当前的省份的可用状态嘛', {
            btn: ['确定', '取消'] //按钮
        }, function (cindex) {
            console.info("用户确定要删除")
            $.ajax({
                type: 'post',
                url: 'modifyProvince',
                data: {id: id, status: status},
                dataType: 'json',
                success: function (res) {
                    console.info(res)
                    window.parent.location.reload();
                }
            })
            layer.close(cindex)
        }, function (cindex) {
            console.info("用户取消了删除操作")
            layer.close(cindex)
        });
    }

    $(function () {
        $('.search-bar .dropdown-menu a').click(function () {
            let field = $(this).data('field') || '';
            $('#search-field').val(field);
            $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
        });
    });
</script>
</body>
</html>